package com.wiscamp.ninechapters.problems.math;

import com.wiscamp.ninechapters.common.core.ParseHelper;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 商及余数
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class LatexQuotientReminder extends LatexNumber {
    /**
     * 除法的商
     */
    private int quotient = 0;

    /**
     * 除法的余数
     */
    private int reminder = 0;


    public String getLatex() {
        if (reminder > 0)
            return String.format("%d\\dots%d", quotient, reminder);
        else
            return String.format("%d", quotient);
    }

    public LatexQuotientReminder(int quotient, int reminder) {
        this.quotient = quotient;
        this.reminder = reminder;
    }

    public LatexQuotientReminder(String quotientText, String reminderText) {
        this.quotient = ParseHelper.parseInteger(quotientText);
        this.reminder = ParseHelper.parseInteger(reminderText);
    }

    public LatexQuotientReminder(String content) {
        var text = content.replace("\\dots", ",");
        var array = text.split(",");
        if (array.length == 2) {
            this.quotient = ParseHelper.parseInteger(array[0]);
            this.reminder = ParseHelper.parseInteger(array[1]);
        }
    }
}